Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Tweak grammar of primitive list in externals #415

Merged
merged 1 commit into from
May 25, 2021

Conversation

IwanKaramazow
Copy link
Contributor

Fixes #412

Currently the grammar allows for a list of primitives in an external declaration: i.e. "hi" "hx" in external f: (int, int) => int = "hi" "hx". This stems from the fact that user primitives with arity greater than 5 should be implemented by two C functions. The first function, to be used in conjunction with the bytecode compiler ocamlc, receives two arguments: a pointer to an array of OCaml values (the values for the arguments), and an integer which is the number of arguments provided. The other function, to be used in conjunction with the native-code compiler ocamlopt, takes its arguments directly.

However in the case of compiling to JS with ReScript, we don't need to deal with this. In order to reduce some complexity, we'll now parse just one primitive.

Fixes #412

Currently the grammar allows for a list of primitives in an external declaration: i.e. `"hi" "hx"` in `external f: (int, int) => int = "hi" "hx"`. This stems from the fact that user primitives with arity greater than 5 should be implemented by two C functions. The first function, to be used in conjunction with the bytecode compiler ocamlc, receives two arguments: a pointer to an array of OCaml values (the values for the arguments), and an integer which is the number of arguments provided. The other function, to be used in conjunction with the native-code compiler ocamlopt, takes its arguments directly. However in the case of compiling to JS, we don't need to deal with this. In order to reduce some complexity, we'll now parse just one primitive.
@IwanKaramazow
Copy link
Contributor Author

cc @bobzhang

2 │ external setTimeout: (unit => unit, int) => float =
3 │

An external requires the name of the JS value you're referring to, like "setTimeout".
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @bloodyowl, how does this sound? 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this only occur with:

external setTimeout: (unit => unit, int) => float =

or also with

external setTimeout: (unit => unit, int) => float

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently only implemented for the first. Can also add one for the latter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go for:

2 | external setTimeout: (unit => unit, int) => float =
3 |
This external is missing the JavaScript value it is supposed to reference (like `= "setTimeout"`)

But the one is your PR looks good to me as well 😊

@bobzhang
Copy link
Member

bobzhang commented May 18, 2021

we may also need consider multiple line string support:

external add : (int,int)=>int = `function add (a,b){
   return a + b
}`

Edit: it seems " already supports multiple line mode?

@IwanKaramazow
Copy link
Contributor Author

Yes, " supports multiline strings because of backwards compatibility. I can add support for strings, but there's currently no way to encode this in the ast. Makes it hard for the printer. Let's stick with"` strings in the short term?

@bobzhang
Copy link
Member

sounds good, as long as we have a way to encode multiple line string, it should be fine

@IwanKaramazow IwanKaramazow merged commit 19f1147 into master May 25, 2021
@IwanKaramazow IwanKaramazow deleted the cleanup-primitive-parsing branch May 25, 2021 10:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not allowing such syntax
3 participants